<template>    
  <component :is="ele" v-model="v" v-bind="propv">
    <!-- {{pp.innerText}} -->
  </component>  
  <el-form v-model="propv">
  <el-form-item v-for="item in pp" :label="item.id" :key="item.id">    
    <el-select v-model="propv[item.id]" v-if="item.options">
      <el-option v-for="o in item.options" :key="o" :label="o" :value="o"></el-option>
    </el-select>
    <el-switch v-model="propv[item.id]" v-else-if="item.type===Boolean"></el-switch>
    <el-input-number v-model="propv[item.id]" v-else-if="item.type===Number"></el-input-number>
    <el-input v-model="propv[item.id]" v-else></el-input>    
  </el-form-item>
  </el-form>
</template>

<script>
import cfg from '../config/componentsProps'
export default {  
  created(){
    console.log('created');
    this.pp=cfg[this.ele]
    this.pp.forEach(element => {      
      let v=element.default
      if(v===undefined){
        v=""
      }
      if(element.type===String){        
        this.propv[element.id]=v
      }
      else if(element.type===String|Number){
        this.propv[element.id]=v
      }
      else if (element.type===Boolean){
        this.propv[element.id]=false
      }
      else if (element.type===Number){
        this.propv[element.id]=0
      }
    });

    console.log(this.propv);
  },
  data(){
    return {
      v:"",      
      propv:{        
      },
      ele:"ElButton", //ElSwitch ElButtonn ElInput
      pp:[]
    }
  }
}
</script>

<style>

</style>